package com.briup.cms.web.controller;

import com.briup.cms.service.IBaseUserService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "用户登录")
@RestController
public class LoginController {
    @Autowired
    private IBaseUserService service;

    /**
     * 测试阶段
     * @GetMapping("/login/{username}/{password}")
     * @PathVariable("username")
     * @param username
     * @param password
     * @return 错误信息/正确信息
     */

    @ApiOperation("根据用户姓名和密码登陆")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "用户名",dataType = "String"),
            @ApiImplicitParam(name = "password",value = "密码",dataType = "String")
    })
    @PostMapping("/login")
    public Message login(String username, String password){
        String token = null;
        token = service.login(username,password);
        return MessageUtil.success(token);

    }

    @ApiOperation("退出登陆")
    @PostMapping("/logout")
    public Message logout(){
        return MessageUtil.success();

    }
}
